//
//  zen_font.hpp
//  font
//
//  Created by MeherTj on 2021/7/7.
//  Copyright © 2021 lover. All rights reserved.
//

#pragma once

#include <vector>
#include <map>
#include <memory>
#include "zen_exception.h"
#include "zen_image.h"

namespace Zen
{

	/// Truetype font decoder.
	class TrueType
	{
	protected:
		TrueType() = default;
		virtual ~TrueType() = default;

	public:
		/// font metrics. with a high-resolution size.
		///  multiply a scale to Get the pixel size.
		struct VMetrics
		{
			float height = 0;
			float ascent = 0; // + on top.
			float lineGap = 0;
			// height = ascent - descent
			// line_height = lineGap + height
		};

		/// the values were scaled.
		///  always pixels.size() == w * h.
		struct Bitmap
		{
			int w = 0, h = 0, x = 0, y = 0;
			int x_advance = 0;
			std::vector<uint8_t> pixels;
		};

		static std::shared_ptr<TrueType> Generate();

		virtual void initFont(std::vector<uint8_t> value) = 0;

		///
		virtual int GetGlyphIndex(int unicode_codepoint) = 0;

		virtual int GetXAdvance(int glyph, float height) = 0;

		virtual Bitmap GetGlyphBitmap(int glyph, float height) = 0;

		virtual VMetrics GetFontMetrics() = 0;
	};
} // namespace Zen
